package org.groupg.project.Indicator;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class Main {
    public static void main(String[] args) {
        IndicatorProcessor processor = new IndicatorProcessor();

        // 模拟多个生产者线程
        int producerCount = 10;
        ExecutorService producerExecutor = Executors.newFixedThreadPool(producerCount);

        // 模拟1000个指标
        for (int i = 0; i < 1000; i++) {
            final int index = i;
            producerExecutor.submit(() -> {
                String indicatorName = "Indicator-" + index;
                Object indicatorData = generateDataForIndicator(index);

                // 发布指标到Disruptor
                processor.publishIndicator(indicatorName, indicatorData);
            });
        }

        // 等待所有指标处理完成
        try {
            producerExecutor.shutdown();
            producerExecutor.awaitTermination(1, TimeUnit.MINUTES);
            Thread.sleep(2000); // 给消费者一些时间处理剩余事件
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } finally {
            processor.shutdown();
        }
    }

    private static Object generateDataForIndicator(int index) {
        // 生成模拟数据
        return "Data for indicator " + index;
    }
}